#pragma once

#include <vector>
#include <map>

#include "Message.h"
#include "NodeInfo.h"

namespace PC2
{

class Socket;
class TransactionInfoSet;
class PC2DataStore;

#define _TIMEOUT_MS 3000

class PC2Node
{
public:
	PC2Node(NodeInfo const& aInfo);
	PC2Node(NodeInfo const& aInfo, std::vector<NodeInfo> const& aParticipantIDSet, char const* apDBPath);
	virtual ~ PC2Node();

public:
	PC2DataStore* GetDataStore();
	
public:
	bool WaitForData(Trans* apTrans, std::string* apData, int32_t aTimeout, char* apSrcAddr = NULL, unsigned short* apSrcPort = NULL);
	void SendTrans(NodeInfo* apNode, Trans* apTrans);

protected:
	void HandleDecisionRequest(TransactionInfoSet* apInfoSet, Trans* apReceivedTrans, char const* apRemoteIP, unsigned short aPort);


protected:
	NodeInfo m_Info;
	Socket* m_pSocket;
	

protected:
	PC2DataStore* m_pStore;
	std::map<uint32_t, NodeInfo> m_Parts;
};

}